<template>
	<view class="ikz-school">
		<ikz-loading :css-data="loading_css"></ikz-loading>
		<ikz-topbg></ikz-topbg>
		<view class="ikz-seach">
			<image class="ikz-search-img" src="/static/campus/search.png"></image>
			<input class="ikz-search-input" placeholder="请输入关键词搜索社区" @input="eventHandle" />
		</view>
		<image class="ikz-top-bg" :src="service_img" mode="widthFix"></image>
		<ikz-list :show-data="list_data" :css-data="list_css" @returnList="returnList"></ikz-list>
	</view>
</template>

<script>
	import ikzLoading from '@/pages/Component/Public/Loading/loading.vue';
	import ikzList from '@/pages/Component/Public/List/public/list/list.vue';
	import ikzTopbg from '@/pages/Component/Public/Topbg/public/topbg/topbg.vue';
	var app = getApp();
	import ikz from '@/pages/Common/tools.js';
	export default {
		components: {
			ikzList,
			ikzLoading,
			ikzTopbg
		},
		data() {
			return {
				list_data: {
					list: app.globalData.agent_list
				},
				list_css: {
					background_color: '#fff',
					border_radius: 15
				},
				loading_css: {
					display: 'flex',
				},
				service_img:app.globalData.service_img,
			}
		},
		created() {
			// var that = this;
			this.loading_css.display = 'none';
		},
		methods: {
			//搜索框
			eventHandle(e) {
				console.log(e.detail.value)
				var path = '/xyb/agent/index';
				var data = {
					li_agent_area: e.detail.value
				}
				ikz.post(path, data, res => {
					if (res.data.code) {
						var temp_data = res.data.data.data;
						var temp_info = [];
						for (var i = 0; i < temp_data.length; i++) {
							var temp = {
								title: temp_data[i].agent_area,
								id: temp_data[i].id
							}
							temp_info.push(temp)
						}
						this.list_data = {
							list: temp_info
						}
					} else {
						uni.showModal({
							title: '提示',
							content: '服务器繁忙，请稍后再试',
							showCancel: false,
							success: function(res) {}
						});
					}
				})
			},
			//点击组件返回
			returnList(e) {
				uni.showModal({
					title: '提示',
					content: '是否选择' + e.title,
					success: function(res) {
						cancel: true
						confirm: false
						if (res.confirm) {
							try {
								console.log(e)
								uni.setStorageSync('default_agent', e);
							} catch (e) {
								// error
							}
							// if (getCurrentPages().length != 0) {
							// getCurrentPages()[0].onLoad();
							//   getCurrentPages()[getCurrentPages().length - 1].onShow();
							// }
							app.globalData.default_agent = e;
							if (getCurrentPages().length == 1) {
								uni.switchTab({
									url: "/pages/Home/index"
								})
							} else {
								getCurrentPages()[0].onLoad();
								uni.navigateBack({
									delta: 1
								});
							}
						}

					},
					fail: function(res) {

					}
				});
			},
		}
	};
</script>

<style>
	page {
		width: 100%;
		height: 100%;
		background: #F3F3F3;
	}

	.ikz-school {
		width: 100%;
		height: 100%;
	}

	.ikz-top-bg {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: -1;
	}

	.ikz-seach {
		width: 80%;
		margin: 30rpx auto;
		border-radius: 50rpx;
		background-color: #fff;
		height: 80rpx;
		display: flex;
		align-items: center;

	}

	.ikz-search-img {
		width: 40rpx;
		height: 40rpx;
		margin: 0 30rpx;
	}
</style>
